//
//  NSDate+Extension.m
//  s.
//
//  Created by 谈虎啸 on 2022/8/29.
//  Copyright © 2022 J. All rights reserved.
//

#import "NSDate+Extension.h"

@implementation NSDate (Extension)
- (NSString *)toFmtString:(NSString *)style
{
    return [MBDateManager dateTransformString:self style:style];
}

/*
 Calendar
 Year: 2017
 Month: 10
 Leap month: no
 Day: 11
 Hour: 16
 Minute: 16
 Second: 39
 Weekday: 4     这个值需要减一
 */
- (NSDateComponents *)toComps
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
//    NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitWeekday;
    NSDateComponents *cmps = [calendar components:unit fromDate:self];
    return cmps;
}


-(NSString *)toTimestamp10
{
    return [NSString stringWithFormat:@"%lld", (long long)[self timeIntervalSince1970]];
}
-(NSString *)toTimestamp13
{
    return [NSString stringWithFormat:@"%lld", (long long)([self timeIntervalSince1970] * 1000)];
}
@end
